<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                template="./../templates/StakeholderPortalTemplate.xhtml">

    <ui:define name="content">
        <f:view beforePhase="#{mealManagerBean.initUpdateMeal}"/>
        <h:form id="list" style="position: relative; float:left; width: 200px;">  
            <p:dataTable var="mealList" value="#{mealManagerBean.mealList}" paginator="true" rows="15"  
                         selection="#{mealManagerBean.selectedMeal}" selectionMode="single"  
                         onRowSelectUpdate="formPrice formPriceControl formMain formAvail" rowSelectListener="#{mealManagerBean.selectProduct}"
                         emptyMessage ="No meal found." style="width:180px">  

                <f:facet name="header">  
                    List of Meals  
                </f:facet>  
  
                <p:column sortBy="#{mealList.name}" filterBy="#{mealList.name}">  
                    <f:facet name="header">  
                        <h:outputText value="Meal Name" />  
                    </f:facet>  
                    <h:outputText value="#{mealList.name}" />  
                </p:column>  
            </p:dataTable> 
        </h:form> 
    </ui:define>
    <ui:define name="contentMeal">
        <h:form id="formMain" style="position: relative; float:left; width: 600px;" rendered="#{mealManagerBean.selectedProduct != null}">
                <h:panelGrid  >
                    <f:metadata>
                        <f:viewParam name ="visibility" value ="#{mealManagerBean.selectedMeal.visibility}" />
                    </f:metadata>

                    <h:outputLabel for="mealName" style="font-weight: bold" value="Meal Name: " />
                    <h:inputText id="mealName" value="#{mealManagerBean.selectedMeal.name}">
                    </h:inputText>
                    <p:message for="mealName" />


                    <h:outputLabel for="originalPrice" style="font-weight: bold" value="Original Price: " />
                    <h:inputText id="originalPrice" value="#{mealManagerBean.selectedMeal.originalPrice}">
                    </h:inputText>
                    <p:message for="originalPrice" />

                    <h:outputLabel for="description" style="font-weight: bold" value="Description: " />
                    <p:inputTextarea id="description" value="#{mealManagerBean.selectedMeal.description}" style="width:300px">
                    </p:inputTextarea>
                    <p:message for="description" />

                    <h:outputLabel for="videoLink" style="font-weight: bold" value="Video Link: " />
                    <h:inputText id="videoLink" value="#{mealManagerBean.selectedMeal.videoLink}">
                    </h:inputText>
                    <p:message for="videoLink" />

                    <h:outputLabel for="visisbility" style="font-weight: bold" value="Visible to Customers: " />
                    <h:outputText id="visisbility" value="#{mealManagerBean.selectedMeal.visibility}">
                    </h:outputText>
                    <p:message for="visisbility" />                  
                    <p:button value="Enable" disabled="#{mealManagerBean.selectedMeal.visibility}" outcome="StakeholderUpdateSelectedMeal">
                        <f:param name="visibility" value="true" />
                    </p:button>
                    <p:button value="Disable" disabled="#{!mealManagerBean.selectedMeal.visibility}" outcome="StakeholderUpdateSelectedMeal">
                        <f:param name="visibility" value="false" />
                    </p:button>


                    <h:outputLabel for="image" style="font-weight: bold" value="Meal Image: " />
                    <h:graphicImage id="gi" alt="The image could not be found."   value="/images/#{mealManagerBean.selectedMeal.imageLink}" width="650" height="450"></h:graphicImage>

                    <p:fileUpload id="upload" fileUploadListener="#{mealManagerBean.handleImageUploadMeal}" 
                                  allowTypes="*.jpg;*.png;*.gif;" description="Images" update ="msg gi"/>     
                    <p:growl id="msg" />

                </h:panelGrid>
                <p:commandButton id="btn1" value="Save Meal Update" update="accordion list" actionListener="#{mealManagerBean.updateMeal}" ajax="true" />
                <p:commandButton id="btn2" value="Delete Meal" update="accordion list" actionListener="#{mealManagerBean.deleteMeal}" ajax="true" />
        </h:form>

   
    </ui:define>
</ui:composition>